#include "dbtablemanager.h"

#include "systemlogtable.h"

DBTableManager::DBTableManager(QObject *parent) :
    QObject(parent)
{
}

DBTableManager::~DBTableManager()
{
}

void DBTableManager::InitAllTable(const QString &connectionName)
{
    m_ConnectName = connectionName;

    m_TableFuncHash.clear();

    m_TableFuncHash.insert(DataOperate::e_SystemLogRecord, &SystemLogTable::AppendSystemLog);
    m_TableFuncHash.insert(DataOperate::e_SystemLogDeleteByID, &SystemLogTable::DeleteSystemLog);
    m_TableFuncHash.insert(DataOperate::e_SystemLogQueryByDate, &SystemLogTable::QuerySystemLogByDate);
}

bool DBTableManager::DataBaseOperate(DataOperate &DataOpera)
{
    qInfo() << "DataBaseOperate" << DataOpera.OperaFunc;

    if(m_TableFuncHash.contains(DataOpera.OperaFunc))
    {
        bool ret = (*(m_TableFuncHash.value(DataOpera.OperaFunc)))(m_ConnectName, DataOpera.OperaArgs, DataOpera.OperaRet);
        qInfo() << "DataBaseOperate table operate:" << ret;
        return ret;
    }
    qWarning() << "DataBaseOperate: no such funcation";
    return false;
}
